package com.lsh.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @author ：LiuShihao
 * @date ：Created in 2020/8/17 9:03 上午
 * @desc ：kafak消费者
 */
@Component
@Slf4j
public class KafkaConsumer2 {

    /**
     * 定义此消费者接收topics = "demo"的消息，与controller中的topic对应上即可
     * @param record 变量代表消息本身，可以通过ConsumerRecord<?,?>类型的record变量来打印接收的消息的各种信息
     */
    @KafkaListener(topics = "aliyun")
    public void listen (ConsumerRecord<String, String> record){
        System.out.println("云服务器的主题："+record.topic()+"___消息："+record.value());
    }
    @KafkaListener(topics = "first")
    public void listen2 (ConsumerRecord<String, String> record){
        System.out.println("集群："+record.topic()+"___消息："+record.value());
    }
}
